Skip to contentSkip to conversation

Change in openvpn[master]: Make unit tests -Wconversion clean

Openvpn-devel In review flichtenheld (Code Review) 2 participants 7 messages Sep 22, 2025 – Sep 24, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1758555758000.Iab9e780d9649d7581e5f6aa4b23e72bbed5e145b@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1205?usp=email

to review the following change.

Change subject: Make unit tests -Wconversion clean
......................................................................

Make unit tests -Wconversion clean

Only trivial problems left after the other patches have been merged.

Change-Id Iab9e780d9649d7581e5f6aa4b23e72bbed5e145b

---
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_ssl.c

2 files changed, 4 insertions(+), 22 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/05/1205/1

tests/unit_tests/openvpn/test_crypto.c +4 -13
index 22e6912..93dfa42 100644
@@ -674,15 +674,10 @@
     struct crypto_options co;
 };
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static int
 crypto_test_epoch_setup(void **state)
 {
-    int *num_future_keys = (int *)*state;
+    uint16_t *num_future_keys = (uint16_t *)*state;
     struct epoch_test_state *data = calloc(1, sizeof(struct epoch_test_state));
 
     data->gc = gc_new();
@@ -699,10 +694,6 @@
     return 0;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 static int
 crypto_test_epoch_teardown(void **state)
 {
@@ -906,9 +897,9 @@
 int
 main(void)
 {
-    int prestate_num13 = 13;
-    int prestate_num16 = 16;
-    int prestate_num32 = 32;
+    uint16_t prestate_num13 = 13;
+    uint16_t prestate_num16 = 16;
+    uint16_t prestate_num32 = 32;
 
     openvpn_unit_test_setup();
     const struct CMUnitTest tests[] = {
tests/unit_tests/openvpn/test_ssl.c +0 -9
index ed40a7d..bb02fcc 100644
@@ -133,11 +133,6 @@
     const char *keyfile;
 } global_state;
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static int
 init(void **state)
 {
@@ -159,10 +154,6 @@
     return 0;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 static int
 cleanup(void **state)
 {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1205?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iab9e780d9649d7581e5f6aa4b23e72bbed5e145b
Gerrit-Change-Number: 1205
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1205?usp=email

to look at the new patch set (#2).

Change subject: Make unit tests -Wconversion clean
......................................................................

Make unit tests -Wconversion clean

Only trivial problems left after the other patches have been merged.

Change-Id Iab9e780d9649d7581e5f6aa4b23e72bbed5e145b

---
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_ssl.c

2 files changed, 9 insertions(+), 24 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/05/1205/2

tests/unit_tests/openvpn/test_crypto.c +4 -13
index 22e6912..93dfa42 100644
@@ -674,15 +674,10 @@
     struct crypto_options co;
 };
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static int
 crypto_test_epoch_setup(void **state)
 {
-    int *num_future_keys = (int *)*state;
+    uint16_t *num_future_keys = (uint16_t *)*state;
     struct epoch_test_state *data = calloc(1, sizeof(struct epoch_test_state));
 
     data->gc = gc_new();
@@ -699,10 +694,6 @@
     return 0;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 static int
 crypto_test_epoch_teardown(void **state)
 {
@@ -906,9 +897,9 @@
 int
 main(void)
 {
-    int prestate_num13 = 13;
-    int prestate_num16 = 16;
-    int prestate_num32 = 32;
+    uint16_t prestate_num13 = 13;
+    uint16_t prestate_num16 = 16;
+    uint16_t prestate_num32 = 32;
 
     openvpn_unit_test_setup();
     const struct CMUnitTest tests[] = {
tests/unit_tests/openvpn/test_ssl.c +5 -11
index ed40a7d..8dc9b66 100644
@@ -133,11 +133,6 @@
     const char *keyfile;
 } global_state;
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static int
 init(void **state)
 {
@@ -152,17 +147,16 @@
     {
         fail_msg("make tmpfile for certificate or key data failed (error = %d)", errno);
     }
-    assert_int_equal(write(certfd, unittest_cert, strlen(unittest_cert)), strlen(unittest_cert));
-    assert_int_equal(write(keyfd, unittest_key, strlen(unittest_key)), strlen(unittest_key));
+    /* Awkward casts required for MinGW with -O0 only */
+    assert_int_equal(write(certfd, unittest_cert, (unsigned int)strlen(unittest_cert)),
+                     strlen(unittest_cert));
+    assert_int_equal(write(keyfd, unittest_key, (unsigned int)strlen(unittest_key)),
+                     strlen(unittest_key));
     close(certfd);
     close(keyfd);
     return 0;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 static int
 cleanup(void **state)
 {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1205?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iab9e780d9649d7581e5f6aa4b23e72bbed5e145b
Gerrit-Change-Number: 1205
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-MessageType: newpatchset

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1205?usp=email )

Change subject: Make unit tests -Wconversion clean
......................................................................

Patch Set 4: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1205?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iab9e780d9649d7581e5f6aa4b23e72bbed5e145b
Gerrit-Change-Number: 1205
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 24 Sep 2025 12:41:38 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#4 lore raw

PATCH v4 1/1 Make unit tests -Wconversion clean

In reply to a message not in the archive

From: Frank Lichtenheld <[email protected]...>

Only trivial problems left after the other patches have been merged.

Change-Id Iab9e780d9649d7581e5f6aa4b23e72bbed5e145b

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1205
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1205
This mail reflects revision 4 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>

tests/unit_tests/openvpn/test_crypto.c +4 -13
index 22e6912..93dfa42 100644
@@ -674,15 +674,10 @@
     struct crypto_options co;
 };
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static int
 crypto_test_epoch_setup(void **state)
 {
-    int *num_future_keys = (int *)*state;
+    uint16_t *num_future_keys = (uint16_t *)*state;
     struct epoch_test_state *data = calloc(1, sizeof(struct epoch_test_state));
 
     data->gc = gc_new();
@@ -699,10 +694,6 @@
     return 0;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 static int
 crypto_test_epoch_teardown(void **state)
 {
@@ -906,9 +897,9 @@
 int
 main(void)
 {
-    int prestate_num13 = 13;
-    int prestate_num16 = 16;
-    int prestate_num32 = 32;
+    uint16_t prestate_num13 = 13;
+    uint16_t prestate_num16 = 16;
+    uint16_t prestate_num32 = 32;
 
     openvpn_unit_test_setup();
     const struct CMUnitTest tests[] = {
tests/unit_tests/openvpn/test_ssl.c +5 -11
index ed40a7d..8dc9b66 100644
@@ -133,11 +133,6 @@
     const char *keyfile;
 } global_state;
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static int
 init(void **state)
 {
@@ -152,17 +147,16 @@
     {
         fail_msg("make tmpfile for certificate or key data failed (error = %d)", errno);
     }
-    assert_int_equal(write(certfd, unittest_cert, strlen(unittest_cert)), strlen(unittest_cert));
-    assert_int_equal(write(keyfd, unittest_key, strlen(unittest_key)), strlen(unittest_key));
+    /* Awkward casts required for MinGW with -O0 only */
+    assert_int_equal(write(certfd, unittest_cert, (unsigned int)strlen(unittest_cert)),
+                     strlen(unittest_cert));
+    assert_int_equal(write(keyfd, unittest_key, (unsigned int)strlen(unittest_key)),
+                     strlen(unittest_key));
     close(certfd);
     close(keyfd);
     return 0;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 static int
 cleanup(void **state)
 {
#5 lore raw

[Openvpn-devel] [PATCH applied] Re: Make unit tests -Wconversion clean

And et voila, the first #ifdef/#pragma set disappears again... and since this is unit tests, it's easily testing itself :-)

Your patch has been applied to the master branch.

commit 9db98baf657c0aa6f56154019c531535d3d16ded

Author: Frank Lichtenheld
Date:   Wed Sep 24 14:41:48 2025 +0200
     Make unit tests -Wconversion clean

     Signed-off-by: Frank Lichtenheld <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1205
     Message-Id: <[email protected]...>
     URL: https://sourceforge.net/p/openvpn/mailman/message/59238128/
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#6 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#6) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1205?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by cron2

Change subject: Make unit tests -Wconversion clean
......................................................................

Make unit tests -Wconversion clean

Only trivial problems left after the other patches have been merged.

Change-Id Iab9e780d9649d7581e5f6aa4b23e72bbed5e145b

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1205
Message-Id: <[email protected]...>
URL: https://sourceforge.net/p/openvpn/mailman/message/59238128/

---
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_ssl.c

2 files changed, 9 insertions(+), 24 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/05/1205/6

tests/unit_tests/openvpn/test_crypto.c +4 -13
index 22e6912..93dfa42 100644
@@ -674,15 +674,10 @@
     struct crypto_options co;
 };
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static int
 crypto_test_epoch_setup(void **state)
 {
-    int *num_future_keys = (int *)*state;
+    uint16_t *num_future_keys = (uint16_t *)*state;
     struct epoch_test_state *data = calloc(1, sizeof(struct epoch_test_state));
 
     data->gc = gc_new();
@@ -699,10 +694,6 @@
     return 0;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 static int
 crypto_test_epoch_teardown(void **state)
 {
@@ -906,9 +897,9 @@
 int
 main(void)
 {
-    int prestate_num13 = 13;
-    int prestate_num16 = 16;
-    int prestate_num32 = 32;
+    uint16_t prestate_num13 = 13;
+    uint16_t prestate_num16 = 16;
+    uint16_t prestate_num32 = 32;
 
     openvpn_unit_test_setup();
     const struct CMUnitTest tests[] = {
tests/unit_tests/openvpn/test_ssl.c +5 -11
index ed40a7d..8dc9b66 100644
@@ -133,11 +133,6 @@
     const char *keyfile;
 } global_state;
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static int
 init(void **state)
 {
@@ -152,17 +147,16 @@
     {
         fail_msg("make tmpfile for certificate or key data failed (error = %d)", errno);
     }
-    assert_int_equal(write(certfd, unittest_cert, strlen(unittest_cert)), strlen(unittest_cert));
-    assert_int_equal(write(keyfd, unittest_key, strlen(unittest_key)), strlen(unittest_key));
+    /* Awkward casts required for MinGW with -O0 only */
+    assert_int_equal(write(certfd, unittest_cert, (unsigned int)strlen(unittest_cert)),
+                     strlen(unittest_cert));
+    assert_int_equal(write(keyfd, unittest_key, (unsigned int)strlen(unittest_key)),
+                     strlen(unittest_key));
     close(certfd);
     close(keyfd);
     return 0;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 static int
 cleanup(void **state)
 {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1205?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iab9e780d9649d7581e5f6aa4b23e72bbed5e145b
Gerrit-Change-Number: 1205
Gerrit-PatchSet: 6
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset

#7 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1205?usp=email )

Change subject: Make unit tests -Wconversion clean
......................................................................

Make unit tests -Wconversion clean

Only trivial problems left after the other patches have been merged.

Change-Id Iab9e780d9649d7581e5f6aa4b23e72bbed5e145b

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1205
Message-Id: <[email protected]...>
URL: https://sourceforge.net/p/openvpn/mailman/message/59238128/

---
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_ssl.c

2 files changed, 9 insertions(+), 24 deletions(-)
tests/unit_tests/openvpn/test_crypto.c +4 -13
index 22e6912..93dfa42 100644
@@ -674,15 +674,10 @@
     struct crypto_options co;
 };
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static int
 crypto_test_epoch_setup(void **state)
 {
-    int *num_future_keys = (int *)*state;
+    uint16_t *num_future_keys = (uint16_t *)*state;
     struct epoch_test_state *data = calloc(1, sizeof(struct epoch_test_state));
 
     data->gc = gc_new();
@@ -699,10 +694,6 @@
     return 0;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 static int
 crypto_test_epoch_teardown(void **state)
 {
@@ -906,9 +897,9 @@
 int
 main(void)
 {
-    int prestate_num13 = 13;
-    int prestate_num16 = 16;
-    int prestate_num32 = 32;
+    uint16_t prestate_num13 = 13;
+    uint16_t prestate_num16 = 16;
+    uint16_t prestate_num32 = 32;
 
     openvpn_unit_test_setup();
     const struct CMUnitTest tests[] = {
tests/unit_tests/openvpn/test_ssl.c +5 -11
index ed40a7d..8dc9b66 100644
@@ -133,11 +133,6 @@
     const char *keyfile;
 } global_state;
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static int
 init(void **state)
 {
@@ -152,17 +147,16 @@
     {
         fail_msg("make tmpfile for certificate or key data failed (error = %d)", errno);
     }
-    assert_int_equal(write(certfd, unittest_cert, strlen(unittest_cert)), strlen(unittest_cert));
-    assert_int_equal(write(keyfd, unittest_key, strlen(unittest_key)), strlen(unittest_key));
+    /* Awkward casts required for MinGW with -O0 only */
+    assert_int_equal(write(certfd, unittest_cert, (unsigned int)strlen(unittest_cert)),
+                     strlen(unittest_cert));
+    assert_int_equal(write(keyfd, unittest_key, (unsigned int)strlen(unittest_key)),
+                     strlen(unittest_key));
     close(certfd);
     close(keyfd);
     return 0;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 static int
 cleanup(void **state)
 {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1205?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iab9e780d9649d7581e5f6aa4b23e72bbed5e145b
Gerrit-Change-Number: 1205
Gerrit-PatchSet: 6
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged